<?php
session_start();
if (isset($_SESSION["username"])) {
?>
  <?php require_once('common/header.php'); ?>
  <!--页面主要内容-->
  <main class="lyear-layout-content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-toolbar clearfix">
              <form class="pull-right search-bar" method="get" action="" role="form">
                <div class="input-group">
                  <div class="input-group-btn">
                    <input type="hidden" name="search_field" id="search-field" value="name">
                    <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                      姓名查询 <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                      <!--<li> <a tabindex="-1" href="javascript:void(0)" data-field="title">渠道来源</a> </li>-->
                      <li> <a tabindex="-1" href="javascript:void(0)" data-field="name">姓名查询</a> </li>
                      <li> <a tabindex="-1" href="javascript:void(0)" data-field="phone">收货人号码</a> </li>
                      <li> <a tabindex="-1" href="javascript:void(0)" data-field="order_id ">订单号查询</a> </li>
                    </ul>
                  </div>
                  <input type="text" class="form-control" value="" name="keyword" placeholder="请输入查询信息">
                </div>
              </form>
              <div class="toolbar-btn-action">
                
                 <a class="btn btn-info m-r-5" href="#">提现列表</a>
              </div>
              
            </div>
            <div class="card-body">
              <div class="table-responsive">
                <form name="form1" id="form1" method="post" action="controller/deleteall.php">

                <table class="table table-bordered">
                   <?php
                    include_once("../untils/conn.php");
                    mysqli_query($con, "set names utf8");
                    if ($con) {
                      if ($db) {
                        //获取数据总行数
                        $sql = "select * from withdrawal";
                        $data = mysqli_query($con, $sql);
                        $maxrows = mysqli_num_rows($data);
                        //计算总页数
                        $page_size = 10;  //每页显示数
                        if ($maxrows % $page_size == 0) {
                          $maxpage = (int)($maxrows / $page_size);
                        } else {
                          $maxpage = (int)($maxrows / $page_size) + 1;
                        }
                        //获取当前页
                        if (isset($_GET['curpage'])) {
                          $page = $_GET['curpage'];
                        } else {
                          $page = 1;
                        }
                        //分段取出数据
                        $start = $page_size * ($page - 1);
                        $get_sql = "select * from withdrawal order by id desc limit $start,$page_size";
                        //得到数据显示
                        $data = mysqli_query($con, $get_sql);
                    ?>
                      <thead>
                        <tr>
                          <th>ID</th>
                          <th>提现账号</th>
                          <th>提现方式</th>
                          <th>姓名</th>
                          <th>账号</th>
                          <th>银行</th>
                          <th>支行</th>
                          <th>提现金额</th>
                          <th>打款金额</th>
                          <th>税额</th>
                          <th>申请状态</th>
                          <th>申请时间</th>
                          <th>处理时间</th>
                          <th>备注说明</th>
                          
                
                          <th>操作</th>
                        </tr>
                      </thead>
                      <tbody>
                       <?php
                          while ($row = mysqli_fetch_array($data)) {
                          ?>
                            <tr>
                              <td style="width:1%;">
                                <?php echo $row["id"] ?>
                              </td>
                              <td style="width:1%;">
                                <?php echo $row["proxy_acc"] ?>
                              </td>
                              <td style="width:5%;">
                                    <?php 
                                        if($row["tx_type"] == 0){
                                            echo "微信";
                                        }elseif($row["tx_type"] == 1){
                                            echo "支付宝";
                                        }elseif($row["tx_type"] == 2){
                                            echo "银行卡";
                                        }
                                    ?>
                                </td>

                              <td style="width:10%;"><?php echo $row["tx_name"] ?>
                              </td>
                              <td style="width:5%;"><?php echo $row["tx_acc"] ?>
                              </td>
                               <td style="width:10%;"><?php echo $row["tx_bank_name"] ?>
                              </td>
                              <td style="width:10%;"><?php echo $row["tx_bank_zh"] ?>
                              </td>
                              <td style="width:5%;">￥<?php echo $row["tx_price"] ?>
                              </td>
                              <td style="width:5%;">￥<?php echo $row["dk_price"] ?>
                              </td>
                              <td style="width:5%;"><?php echo $row["tax"] . "%"  ?>
                              </td>
                             <td style="width:5%;">
                                    <?php 
                                        if ($row["state"] == 0) {
                                            echo "待审核";
                                        } elseif ($row["state"] == 1) {
                                            echo "已打款";
                                        } elseif ($row["state"] == 2) {
                                            echo "审核失败";
                                        } else {
                                            echo "未知状态";
                                        }
                                    ?>
                                </td>
                              <td style="width:5%;"><?php echo $date = date('Y-m-d H:i:s', $row["cr_time"]) ?>
                              </td>
                              <td style="width:5%;"><?php  echo $date = date('Y-m-d H:i:s', $row["cl_time"]) ?>
                              </td>
                              <td style="width:10%;"><?php echo $row["notes"] ?>
                              </td>

                              
                              <td style="width:5%;">
                                <?php if ($row["state"] == 0): ?>
                                    <a href="upwith.php?id=<?php echo $row['id'] ?>" class="btn btn-primary btn-sm">审核打款</a>
                                <?php elseif ($row["state"] == 1): ?>
                                    <a href="#" class="btn btn-info btn-sm">已打款</a>
                                <?php elseif ($row["state"] == 2): ?>
                                    <a href="upwith.php?id=<?php echo $row['id'] ?>" class="btn btn-danger btn-sm">重新审核</a>
                                <?php endif; ?>
                            </td>

                          
                          </tr>
                        <?php
                        }
                        ?>
                      </tbody>
                      <tfoot>
                        <tr>
                          <td colspan="12" style="text-align: right;">
                        <?php
                        echo "<p>共 $maxpage 页&nbsp;&nbsp;";
                        echo "每页 $page_size 项&nbsp;&nbsp;";
                        //设置上一页
                        if ($page > 1) {
                          $prepage = $page - 1;
                          echo "<a href='?curpage=$prepage'>上一页</a>&nbsp;&nbsp;";
                        }
                        //设置下一页
                        if ($page < $maxpage) {
                          $nextpage = $page + 1;
                          echo "<a href='?curpage=$nextpage'>下一页</a>&nbsp;&nbsp;";
                        }
                        echo "&nbsp;&nbsp;第 $page 页</p>";
                      }
                    }
                  ?>
                        </td>
                      </tr>
                    </tfoot>
                </table>

                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    </div>
    <script>
        $(document).ready(function(){
            $('.update-btn').click(function(e){
                e.preventDefault();
                var id = $(this).data('id');
                $.ajax({
                    url: 'updatesta.php',
                    type: 'GET',
                    data: {id: id},
                    success: function(data){
                        alert('状态处理成功！');
                    },
                    error: function(jqXHR, textStatus, errorThrown){
                        console.log(textStatus);
                    }
                });
            });
        });
</script>
  </main>
  <!--End 页面主要内容-->
  <?php require_once('common/footer.php'); ?>
<?php
} else {
  echo "<script>alert('您尚未登录，没有权限访问该页面');location.href='login.php';</script>";
}
